package com.kh.pajx.sop.util.common;

import java.util.*;
/**
 * 由原运维系统公共类移入
 * 2014年6月23日14:10:09
 */
public class Change {
	public static String HTMLChange(String source) {
		String changeStr = "";
		if (source == null) {
			return changeStr;
		}
		changeStr = source.trim();
		changeStr = changeStr.replaceAll(" ", "");
		changeStr = changeStr.replaceAll("'", "");
		changeStr = changeStr.replaceAll("\"", "");
		return changeStr;
	}

	public static String delSpace(Object source) {
		String nvalue = "";
		if (source == null) {
			return nvalue;
		}
		nvalue = String.valueOf(source);
		nvalue = nvalue.replaceAll("\\s+", "");
		nvalue = nvalue.toLowerCase();
		return nvalue;
	}

	public static String getValue(Map<String, String> params, String key) {
		if (params == null) {
			return "";
		}
		if (key == null) {
			return "";
		}
		if (params.keySet().size() == 0) {
			return "";
		}
		String val = params.get(key);
		if (val == null) {
			return "";
		}
		val = val.trim();
		if ("null".equals(val)) {
			val = "";
		}
		return val;
	}

	public static String getDaoValue(Map<String, String> params, String key) {
		if (params == null) {
			return "";
		}
		String val = params.get(key);
		if (val == null) {
			return "";
		}
		val = val.trim();
		if ("null".equals(val) || "-1".equals(val)) {
			val = "";
		}
		return val;
	}

	public static String getPage(Object pageObj) {
		String page = String.valueOf(pageObj);
		if (page == null) {
			return "1";
		}
		if (page.matches("\\d+") == false) {
			page = "1";
		}
		return page;
	}

	public static String getPageLink(Object pageLink) {
		if (pageLink == null) {
			return "";
		}
		String val = String.valueOf(pageLink);
		val = val.trim();
		return val;
	}

	@SuppressWarnings("rawtypes")
	public static List getList(Object obj) {
		if (obj == null) {
			return new ArrayList();
		} else {
			return (List) obj;
		}
	}

	public static void initParams(Map<String, String> params) {
		if (params == null) {
			params = new HashMap<String, String>();
		}
	}

	public static String dealNullValue(Object obj) {
		if (obj == null) {
			return "";
		}
		String value = String.valueOf(obj);
		if ("null".equals(value)) {
			return "";
		}
		return value;
	}
}
